package reflect;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
 * @author DBX
 * @effect 获取类属性
 * @date 2021/09/13/22:04
 */
public class ReflectTest05 {
    public static void main(String[] args) throws ClassNotFoundException {
        Class  c = Class.forName("reflect.User");
        String c1 = c.getSimpleName();

        System.out.println("简类名："+c1);

        Field[] str = c.getFields();
        System.out.println(str.length);
        System.out.println(str[0]);



        //可以获取私有属性
        Field[] str1 = c.getDeclaredFields();
        System.out.println(str.length);

        for (Field f : str1){
            int temp = f.getModifiers(); //返回int值
            String modifier = Modifier.toString(temp);

            System.out.print(modifier+" ");
            System.out.print(f.getName()+" ");
            System.out.println(f.getType().getSimpleName()+" ");//获取类属性的类型

        }

    }
}
